<template>
  <view class="recommend-services">
    <view class="section-header">
      <text class="section-title">为您推荐</text>
      <navigator url="/pages/recommend/more" class="view-more">
        更多<text class="icon">></text>
      </navigator>
    </view>
    <view class="recommend-grid">
      <view class="recommend-item"
        v-for="(item, index) in services"
        :key="index"
        @click="onItemClick(item)"
        v-show="index < 6"
      >
        <view class="icon-wrapper">
          <image class="recommend-icon" :src="getIconPath(item.icon)" mode="aspectFill"></image>
        </view>
        <text class="recommend-name">{{item.name}}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, defineProps, defineEmits, computed } from 'vue';

const props = defineProps({
  services: {
    type: Array,
    default: () => []
  },
  iconSize: {
    type: [Number, String],
    default: 100
  }
});

const emit = defineEmits(['itemClick']);

const onItemClick = (item) => {
  emit('itemClick', item);
};

// 获取图标路径
const getIconPath = (icon) => {
  return `/static/icons/${icon}.png`;
};
</script>

<style lang="scss" scoped>
.recommend-services {
  background: #fff;
  border-radius: 16rpx;
  padding: 24rpx 0;

  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 20rpx 20rpx;
    padding: 0 10rpx;

    .section-title {
      font-size: 32rpx;
      font-weight: bold;
    }

    .view-more {
      font-size: 26rpx;
      color: #666;
      display: flex;
      align-items: center;

      .icon {
        margin-left: 4rpx;
        font-size: 22rpx;
      }
    }
  }

  .recommend-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30rpx;
    padding: 0 30rpx;
  }

  .recommend-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    
    .icon-wrapper {
      margin-bottom: 16rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      
      .recommend-icon {
        width: 100rpx;
        height: 100rpx;
        border-radius: 50%;
      }
    }
    
    .recommend-name {
      font-size: 26rpx;
      color: #333;
      max-width: 100%;
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>
